package com.jsjosem.aftersales.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.google.gson.Gson;
import com.jsjosem.aftersales.data.response.NotifyData;
import com.jsjosem.aftersales.ui.notifications.ServiceEventInfoActivity;
import com.jsjosem.aftersales.ui.worktickets.WorkTicketsInfoActivity;

public class NotificationClickReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        String data = extras.getString("data");
        NotifyData notifyData = new Gson().fromJson(data, NotifyData.class);
        Intent newIntent;
        switch (notifyData.getNotify_type()) {
            case "event":
                newIntent = new Intent(context, ServiceEventInfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newIntent.putExtra("eventId", notifyData.getBusiness_id().toString());
                break;
            case "work_order":
                newIntent = new Intent(context, WorkTicketsInfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newIntent.putExtra("workId", notifyData.getBusiness_id().longValue());
                break;
            default:
                // 如果不匹配 就不跳转了
                return;
        }
        // 把数据传递到对应activity
        context.startActivity(newIntent);
    }
}
